/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package fr.ove.openmath.jome.ctrlview.bidim.selection;

/**
 *
 * @author Mr.Sam
 */
import java.util.Vector;
import java.util.Enumeration;
import fr.ove.openmath.jome.ctrlview.bidim.Display;
import fr.ove.openmath.jome.ctrlview.bidim.selection.events.SelectionEvent;
import fr.ove.openmath.jome.ctrlview.bidim.selection.events.SelectionEventListener;


/**
* This class manages a list of selected elements.
*
* @author © 1998 DIRAT Laurent
* @version 1.0  30/06/98
*/
public class SelectionManager implements SelectionEventListener {
    /**
    * The list of selected elements.
    */
    private Vector selected;

    /**
    * The constructor.
    */
    public SelectionManager() {
        selected = new Vector();
    }

    /**
    * Consumes (i.e. treats) the event received.
    * @param selectionEvent the event to consume.
    */
    public void consumeSelectionEvent(SelectionEvent selectionEvent) {
        switch (selectionEvent.getAction()) {
            case SelectionEvent.PURGE :
                selected.setSize(0);
                selected.trimToSize();
                break;
            case SelectionEvent.REMOVE :
                selected.removeElement(selectionEvent.getArgument());
                break;
            case SelectionEvent.ADD :
                selected.addElement(selectionEvent.getArgument());
                break;
            case SelectionEvent.GET_SELECTION_SIZE :
                selectionEvent.setArgument(new Integer(selected.size()));
                break;
            case SelectionEvent.GET_SELECTION :
                selectionEvent.setArgument(selected.clone());
                break;
            case SelectionEvent.LIST :
            // For debugg only !!!
                System.out.println(" I've got "+ selected.size() + " selected elements");
                for (Enumeration e = selected.elements(); e.hasMoreElements(); )
                    ((Display) e.nextElement()).whoAmI();
                break;
        }
    }
}
